package org.j2se.learn;



import java.util.ArrayList;
import java.util.Arrays;

/**
 * User: 缪凯
 * Date: 11-10-19
 * Time: 下午3:51
 *
 * 随机数发生器学习：
 * 1、生成随机数
 * 2、舍入随机小数
 *
 */
public class RandomGenerator {
    private int[] result = new int[5];

    public int[] getFiveNumberOfOrder(ArrayList<Integer> source){
        int[] resultForOrder = Arrays.copyOf(this.getFiveNumber(source), 5);
        Arrays.sort(resultForOrder); //排序数组
        return resultForOrder;
    }

    public int[] getFiveNumber(ArrayList<Integer> source){
        if(source != null && source.size() >= 5){
            ArrayList<Integer> clone = (ArrayList<Integer>)source.clone();
            double location = -1;
            int correct = 1;
            for(int i = 0 ; i < 5 ; i++){
                location = Math.round(Math.random() * (clone.size() - correct));
                result[i] = clone.remove((int)location);
            }
        }
        return this.result;
    }

    public static String NumbertoString(int[] numbers){
        StringBuilder stringBuilder = new StringBuilder();
        if(numbers != null && numbers.length > 0){
            for (int number : numbers) {
                stringBuilder.append(number).append(" ");
            }
        }
        return stringBuilder.toString();
    }


    public static void main(String[] args){
//        RandomGenerator rg = new RandomGenerator();
//        ArrayList<Integer> source = new ArrayList<Integer>();
//        for(int i = 0 ; i < 11 ; i++)
//            source.add(i + 1);

        for(int i = 0 ; i < 100 ; i++)
//            System.out.println(Math.round(Math.random() * 1000000000) % 11);
        System.out.println(Math.round(((Math.random() * 10000000) / 4.6692016)) % 11);
    }
}
